home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / password.txt < prev    next >
Text File  |  1992-10-14  |  3KB  |  74 lines

  1. October 10, 1992
  2. by Raymond W. Six
  3. CompuServe: 70530,433
  4.  
  5. Here's a way to create a 'Password' style text box completely with
  6. VB/DOS code - no custom controls.  Any questions, comments, and/or
  7. suggestions welcomed.
  8.  
  9. Do This:
  10.  
  11. 1)  Create a normal TEXT BOX control to use for the password box.
  12.     {let's name it Password_Text for this example}
  13.  
  14. 2)  Create a LABEL control and name it PasswordDisplay_Label.
  15.  
  16. 3)  Enlarge the form and move Password_Text over past what was the
  17.     edge of the form, then change to form size back so that the
  18.     Password_Text control is no longer visible.  DO NOT CHANGE THE
  19.     VISIBLE OR ENABLED PROPERTIES OF Password_Text.
  20.  
  21. 4)  Set the BorderStyle of PasswordDisplay_Label to Fixed-Single.
  22.  
  23. 5)  Position and size PasswordDisplay_Label however you would like
  24.     the password box to appear to the user.
  25.  
  26. 6)  Add this code to Password_Text's 'Change' event:
  27.  
  28.     SUB Password_Text_Change()
  29.          PasswordDisplay_Label.Caption = STRING$(LEN(Password_Text.Text),"*")
  30.     END SUB
  31.  
  32. 7)  Add this code to Password_Text's 'GotFocus' event:
  33.  
  34.     SUB Password_Text_GotFocus()
  35.          PasswordDisplay_Label.BorderStyle = 2
  36.     END SUB
  37.  
  38. 8)  Add this code to Password_Text's 'LostFocus' event:
  39.  
  40.     SUB Password_Text_LostFocus()
  41.          PasswordDisplay_Label.BorderStyle = 1
  42.     END SUB
  43.  
  44. 9)  Add this code to PasswordDisplay_Label's 'Click' event:
  45.  
  46.     SUB PasswordDisplay_Label_Click()
  47.          Password_Text.SETFOCUS
  48.     END SUB
  49.  
  50. Here's the way it works:
  51.  
  52. Even though the actual Password_Text TEXT BOX is not visible on the screen,
  53. users may still tab into it (i.e. it may still get the 'Focus').  Also,
  54. keystrokes may still be entered into this control - which cause a 'Change'
  55. event - which (via the code we put in) will update the 'fake' password box
  56. (PasswordDisplay_Label) to look like a 'Password' style text box.
  57.  
  58. One problem that occurs is that no 'Caret' (typing cursor) will appear in
  59. the 'fake' password box.  This makes it difficult for the user to tell
  60. which control has the focus.  That's where the GetFocus and LostFocus code
  61. comes in.
  62.  
  63. When Password_Text gets the 'Focus', the BorderStyle of the fake password
  64. box (PasswordDisplay_Label) will be changed to Fixed-Double.  The reverse
  65. will occur when 'Focus' shifts AWAY from Password_Text.
  66.  
  67. In case the user decides to use the mouse to change focus to the password
  68. box, the code placed in the 'fake' password box will re-direct focus to
  69. Password_Text instead.
  70.  
  71. October 10, 1992
  72. by Raymond W. Six
  73. CompuServe: 70530,433
  74.